<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL 数据库优化技巧</title>
    <meta name="description" content="MySQL 是最流行的关系型数据库之一，分享一些数据库优化的实用技巧。">
    <meta name="keywords" content="Redis">
    
    <!-- Tailwind CSS CDN -->
    <script src="/static/js/tailwind.min.js"></script>
    
    <!-- Font Awesome CDN -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- 自定义CSS -->
    <link rel="stylesheet" href="/static/css/style.css">
    
    <!-- 额外的CSS -->
    
<!-- 代码高亮样式 -->
<link rel="stylesheet" href="/static/css/highlight-github.min.css">

</head>
<body>
    <!-- 头部导航 - 使用 Tailwind CSS -->
    <header class="bg-white shadow-lg border-b border-gray-200">
        <nav class="max-w-7xl mx-auto px-8">
            <div class="flex justify-between items-center h-16">
                <!-- Logo -->
                <a href="/" class="flex items-center text-xl font-bold text-gray-800 hover:text-blue-600 transition-colors">
                    <img src="/static/images/logo.svg" alt="个人博客" class="h-24 w-24">
                </a>
                
                <!-- 搜索框 -->
                <div class="flex-1 max-w-md mx-8">
                    <form id="search-form" action="/search" method="GET" class="relative">
                        <input type="text" id="search-input" name="q" placeholder="搜索文章..." 
                               class="w-full px-4 py-2 pl-10 pr-4 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                        <button type="submit" class="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600">
                            <i class="fas fa-search"></i>
                        </button>
                    </form>
                </div>
                
                <!-- 导航菜单 -->
                <div class="flex items-center space-x-6">
                    <a href="/" class="text-gray-700 hover:text-blue-600 font-medium transition-colors">
                        <i class="fas fa-home mr-1"></i>首页
                    </a>
                    <a href="/about" class="text-gray-700 hover:text-blue-600 font-medium transition-colors">
                        <i class="fas fa-user mr-1"></i>关于
                    </a>
                    <a href="/contact" class="text-gray-700 hover:text-blue-600 font-medium transition-colors">
                        <i class="fas fa-envelope mr-1"></i>联系
                    </a>
                    
                    
                        <a href="#" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors">
                            <i class="fas fa-sign-in-alt mr-1"></i>登录
                        </a>
                    
                </div>
            </div>
        </nav>
    </header>

    <!-- 主要内容 -->
    <main class="min-h-screen bg-gray-50">
        <div class="max-w-7xl mx-auto px-8 py-8">
            
<!-- 文章头部 -->
<article class="bg-white rounded-xl shadow-lg overflow-hidden mb-8">
    <!-- 文章封面 -->
    
    <div class="aspect-w-16 aspect-h-9">
        <img src="https://images.unsplash.com/photo-1544383835-bda2bc66a55d?w=800&amp;h=400&amp;fit=crop" alt="MySQL 数据库优化技巧" class="w-full h-64 object-cover">
    </div>
    
    
    <div class="p-8">
        <!-- 文章标题 -->
        <header class="mb-8">
            <h1 class="text-4xl font-bold text-gray-900 mb-4 leading-tight">MySQL 数据库优化技巧</h1>
            
            <!-- 文章元信息 -->
            <div class="flex flex-wrap items-center gap-6 text-gray-600 mb-6">
                <div class="flex items-center gap-2">
                    <img src="/static/images/default-avatar.svg" 
                         alt="管理员" 
                         class="w-8 h-8 rounded-full object-cover">
                    <span class="font-medium">管理员</span>
                </div>
                
                <div class="flex items-center gap-1">
                    <i class="fas fa-calendar-alt text-sm"></i>
                    <time datetime="2025-10-09T11:24:41.006833">
                        2025年10月09日
                    </time>
                </div>
                
                <div class="flex items-center gap-1">
                    <i class="fas fa-eye text-sm"></i>
                    <span id="view-count">0 次阅读</span>
                </div>
                
                <div class="flex items-center gap-1">
                    <i class="fas fa-heart text-sm"></i>
                    <span id="like-count-display">0 个赞</span>
                </div>
                
                <div class="flex items-center gap-1">
                    <i class="fas fa-comment text-sm"></i>
                    <span id="comment-count-display">0 条评论</span>
                </div>
            </div>
            
            <!-- 文章标签 -->
            
            <div class="flex flex-wrap gap-2 mb-6">
                
                <span class="inline-block bg-blue-100 text-blue-800 text-sm px-3 py-1 rounded-full mr-2 mb-2">
                    <i class="fas fa-tag mr-1"></i>Redis
                </span>
                
            </div>
            
            
            <!-- 文章摘要 -->
            
            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded-r-lg mb-6">
                <p class="text-gray-700 italic">MySQL 是最流行的关系型数据库之一，分享一些数据库优化的实用技巧。</p>
            </div>
            
        </header>
        
        <!-- 文章内容 -->
        <div class="prose prose-lg max-w-none prose-headings:text-gray-900 prose-p:text-gray-700 prose-a:text-blue-600 prose-strong:text-gray-900 prose-code:text-pink-600 prose-code:bg-gray-100 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-pre:bg-gray-900 prose-pre:text-gray-100">
            <h1 id="mysql">MySQL 数据库优化技巧</h1>
<p>MySQL 是最流行的关系型数据库之一，掌握优化技巧很重要。</p>
<h2 id="_1">索引优化</h2>
<h3 id="_2">创建合适的索引</h3>
<pre class="codehilite"><code class="language-sql">-- 单列索引
CREATE INDEX idx_user_email ON users(email);

-- 复合索引
CREATE INDEX idx_user_name_email ON users(name, email);

-- 唯一索引
CREATE UNIQUE INDEX idx_user_username ON users(username);
</code></pre>

<h3 id="_3">索引使用原则</h3>
<ul>
<li>经常用于 WHERE 条件的列</li>
<li>经常用于 ORDER BY 的列</li>
<li>经常用于 JOIN 的列</li>
<li>避免在小表上创建索引</li>
</ul>
<h2 id="_4">查询优化</h2>
<h3 id="explain">使用 EXPLAIN 分析</h3>
<pre class="codehilite"><code class="language-sql">EXPLAIN SELECT * FROM users WHERE email = 'user@example.com';
</code></pre>

<h3 id="_5">避免全表扫描</h3>
<pre class="codehilite"><code class="language-sql">-- 不好的查询
SELECT * FROM users WHERE YEAR(created_at) = 2023;

-- 优化的查询
SELECT * FROM users WHERE created_at &gt;= '2023-01-01' AND created_at &lt; '2024-01-01';
</code></pre>

<h3 id="limit">使用 LIMIT</h3>
<pre class="codehilite"><code class="language-sql">-- 限制结果数量
SELECT * FROM users ORDER BY created_at DESC LIMIT 10;
</code></pre>

<h2 id="_6">表结构优化</h2>
<h3 id="_7">选择合适的数据类型</h3>
<pre class="codehilite"><code class="language-sql">-- 使用 TINYINT 而不是 INT
status TINYINT(1) NOT NULL DEFAULT 0

-- 使用 VARCHAR 而不是 TEXT
description VARCHAR(255) NOT NULL
</code></pre>

<h3 id="_8">规范化设计</h3>
<ul>
<li>第一范式：原子性</li>
<li>第二范式：消除部分依赖</li>
<li>第三范式：消除传递依赖</li>
</ul>
<h2 id="_9">配置优化</h2>
<h3 id="_10">内存配置</h3>
<pre class="codehilite"><code class="language-ini"># InnoDB 缓冲池大小
innodb_buffer_pool_size = 1G

# 查询缓存
query_cache_size = 64M
query_cache_type = 1
</code></pre>

<h3 id="_11">连接配置</h3>
<pre class="codehilite"><code class="language-ini"># 最大连接数
max_connections = 200

# 连接超时
wait_timeout = 600
</code></pre>

<h2 id="_12">监控和诊断</h2>
<h3 id="_13">慢查询日志</h3>
<pre class="codehilite"><code class="language-ini"># 启用慢查询日志
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
</code></pre>

<h3 id="_14">性能监控</h3>
<pre class="codehilite"><code class="language-sql">-- 查看当前连接
SHOW PROCESSLIST;

-- 查看表状态
SHOW TABLE STATUS;

-- 查看索引使用情况
SHOW INDEX FROM users;
</code></pre>

<h2 id="_15">总结</h2>
<p>数据库优化是一个持续的过程，需要根据实际使用情况不断调整和优化。</p>
        </div>
        
        <!-- 文章操作 -->
        <div class="flex flex-wrap items-center justify-between gap-4 mt-8 pt-6 border-t border-gray-200">
            <div class="flex items-center gap-4">
                <button id="like-btn" class="flex items-center gap-2 px-4 py-2 bg-gray-50 text-gray-600 rounded-lg hover:bg-red-50 hover:text-red-600 transition-colors">
                    <i class="fas fa-heart"></i>
                    <span class="like-count">0</span>
                    <span>点赞</span>
                </button>
                
                <div class="flex items-center gap-2 px-4 py-2 bg-gray-50 text-gray-600 rounded-lg">
                    <i class="fas fa-comment"></i>
                    <span id="comment-count">0</span>
                    <span>评论</span>
                </div>
            </div>
            
            <div class="flex items-center gap-2">
                <a href="/" class="flex items-center gap-2 px-4 py-2 text-gray-600 hover:text-gray-800 transition-colors">
                    <i class="fas fa-arrow-left"></i>
                    <span>返回首页</span>
                </a>
            </div>
        </div>
    </div>
</article>

<!-- 评论区 -->
<div class="mt-12">
    <div class="flex items-center gap-3 mb-8">
        <div class="h-px bg-gray-300 flex-1"></div>
        <h3 class="text-xl font-semibold text-gray-700 px-4">评论区</h3>
        <div class="h-px bg-gray-300 flex-1"></div>
    </div>
    
    <!-- 评论列表 -->
    <div id="comments-list" class="space-y-6">
        <!-- 评论将通过JavaScript动态加载 -->
    </div>
    
    <!-- 加载更多评论按钮 -->
    <div id="comments-pagination" class="mt-8 text-center hidden">
        <button id="load-more-comments" class="px-6 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors">
            <i class="fas fa-chevron-down mr-2"></i>加载更多评论
        </button>
    </div>
    
    <!-- 发表评论区域 -->
    <div class="mt-8 bg-white border border-gray-200 rounded-lg p-6">
        <div class="flex items-start gap-4">
            <!-- 用户头像 -->
            <div class="w-10 h-10 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center text-white font-semibold text-sm">
                <i class="fas fa-user"></i>
            </div>
            
            <!-- 评论输入框 -->
            <div class="flex-1">
                <div class="flex items-center gap-2 mb-3">
                    <span id="user-status" class="text-sm text-gray-600">以游客身份评论</span>
                </div>
                
                <!-- 评论表单 -->
                <form id="comment-form" class="space-y-4">
                    <!-- 隐藏字段存储文章ID -->
                    <input type="hidden" id="post-id-input" name="post_id" value="11">
                    
                    <div>
                        <textarea id="comment-input" name="content" required placeholder="写下你的评论..." 
                                  class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors resize-none" 
                                  rows="4"></textarea>
                    </div>
                    <div class="flex justify-end">
                        <button type="submit" id="send-comment" class="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium">
                            <i class="fas fa-paper-plane mr-2"></i>发表评论
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

        </div>
    </main>

    <!-- 页脚 - 使用 Tailwind CSS -->
    <footer class="bg-gray-800 text-white">
        <div class="max-w-7xl mx-auto px-8 py-12">
            <div class="grid grid-cols-2 gap-8">
                <div class="space-y-4">
                    <h3 class="text-xl font-bold flex items-center">
                        <i class="fas fa-star text-yellow-500 mr-2"></i>
                        个人博客
                    </h3>
                    <p class="text-gray-300">分享技术心得，记录生活感悟</p>
                    <p class="text-sm text-gray-400">
                        基于 <a href="https://flask.palletsprojects.com/" target="_blank" class="text-blue-400 hover:text-blue-300">Flask</a> 构建 | 
                        主题灵感来自 <a href="https://hexo.io/" target="_blank" class="text-blue-400 hover:text-blue-300">Hexo</a>
                    </p>
                </div>
                <div class="space-y-4">
                    <h4 class="text-lg font-semibold">快速链接</h4>
                    <div class="flex flex-wrap gap-4">
                        <a href="/" class="text-gray-300 hover:text-white transition-colors">
                            <i class="fas fa-home mr-1"></i>首页
                        </a>
                        <a href="/about" class="text-gray-300 hover:text-white transition-colors">
                            <i class="fas fa-user mr-1"></i>关于
                        </a>
                        <a href="/contact" class="text-gray-300 hover:text-white transition-colors">
                            <i class="fas fa-envelope mr-1"></i>联系
                        </a>
                        <a href="https://github.com" target="_blank" class="text-gray-300 hover:text-white transition-colors">
                            <i class="fab fa-github mr-1"></i>GitHub
                        </a>
                    </div>
                </div>
            </div>
            <div class="border-t border-gray-700 mt-8 pt-8 text-center text-gray-400">
                <p>&copy; 2024 个人博客系统. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <!-- 回到顶部按钮 -->
    <button id="scroll-to-top" class="fixed bottom-8 right-8 bg-blue-600 text-white p-3 rounded-full shadow-lg hover:bg-blue-700 transition-all duration-300 opacity-0 invisible">
        <i class="fas fa-arrow-up"></i>
    </button>

    <!-- JavaScript -->
    <script src="/static/js/main.js"></script>
    
    <!-- 额外的JavaScript -->
    
<!-- 代码高亮脚本 -->
<script src="/static/js/highlight.min.js"></script>

<!-- 引入utils.js通知系统 -->
<script src="/static/js/utils.js"></script>

<script>
// 获取文章ID - 移到全局作用域
window.postId = parseInt('11') || 1;
const postId = window.postId;
let currentPage = 1;
let isAdmin = false;
let adminUser = null;
// 回复功能已移除

document.addEventListener('DOMContentLoaded', function() {
    hljs.highlightAll();
    
    // 检查Utils是否已加载
    if (typeof Utils === 'undefined') {
        console.error('Utils未定义，请检查utils.js是否正确加载');
        return;
    }
    
    // 检查登录状态
    checkLoginStatus();
    
    // 初始化
    loadComments();
    setupCommentHandlers();
    setupLoadMoreButton();
    setupLikeButton();
    loadPostStats();
});

// 加载评论
function loadComments(page = 1) {
    const commentsListEl = document.getElementById('comments-list');
    const paginationEl = document.getElementById('comments-pagination');
    const postIdInput = document.getElementById('post-id-input');
    const currentPostId = postIdInput ? parseInt(postIdInput.value) : postId;
    
    fetch(`/api/comments?post_id=${currentPostId}&page=${page}&per_page=10`)
        .then(response => response.json())
        .then(data => {
            if (data.success && data.data.comments.length > 0) {
                if (page === 1) {
                    commentsListEl.innerHTML = '';
                }
                renderComments(data.data.comments);
                
                // 显示/隐藏加载更多按钮
                if (data.data.pagination.has_next) {
                    paginationEl.classList.remove('hidden');
                    document.getElementById('load-more-comments').onclick = () => loadComments(page + 1);
                } else {
                    paginationEl.classList.add('hidden');
                }
            } else if (page === 1) {
                commentsListEl.innerHTML = '<p class="text-gray-500 text-center py-8">暂无评论，快来抢沙发吧！</p>';
            }
        })
        .catch(error => {
            console.error('加载评论失败:', error);
            if (page === 1) {
                commentsListEl.innerHTML = '<p class="text-gray-500 text-center py-8">加载评论失败，请稍后重试</p>';
            }
        });
}

// 渲染评论
function renderComments(comments) {
    const commentsListEl = document.getElementById('comments-list');
    
    comments.forEach(comment => {
        const commentEl = createCommentElement(comment);
        commentsListEl.appendChild(commentEl);
    });
}

// 创建评论元素
function createCommentElement(comment) {
    const date = new Date(comment.created_at).toLocaleString('zh-CN');
    // 判断是否为管理员评论：检查是否为当前管理员用户
    const isAdminComment = adminUser && (comment.author_name === adminUser.name || comment.author_name === adminUser.username);
    const isAnonymous = comment.author_name === '匿名用户';
    
    const commentDiv = document.createElement('div');
    commentDiv.className = 'bg-white border border-gray-200 rounded-lg p-4 hover:shadow-sm transition-shadow';
    commentDiv.innerHTML = `
        <div class="flex items-start gap-3">
            <div class="w-10 h-10 ${isAdminComment ? 'bg-gradient-to-br from-red-500 to-pink-600' : isAnonymous ? 'bg-gradient-to-br from-gray-500 to-gray-600' : 'bg-gradient-to-br from-blue-500 to-purple-600'} rounded-full flex items-center justify-center text-white font-semibold text-sm overflow-hidden">
                ${isAdminComment && adminUser && adminUser.avatar ? 
                    `<img src="${adminUser.avatar}" alt="${escapeHtml(comment.author_name)}" class="w-full h-full object-cover">` : 
                    isAdminComment ? '<i class="fas fa-crown"></i>' : 
                    isAnonymous ? '<i class="fas fa-user-secret"></i>' : 
                    escapeHtml(comment.author_name).charAt(0).toUpperCase()}
            </div>
            <div class="flex-1">
                <div class="flex items-center gap-2 mb-2">
                    <span class="font-semibold text-gray-900">${escapeHtml(comment.author_name)}</span>
                    ${isAdminComment ? '<span class="text-xs bg-red-100 text-red-600 px-2 py-1 rounded-full">管理员</span>' : isAnonymous ? '<span class="text-xs bg-gray-100 text-gray-600 px-2 py-1 rounded-full">匿名</span>' : ''}
                    <span class="text-sm text-gray-500">${date}</span>
                </div>
                <div class="text-gray-700 leading-relaxed mb-3">${escapeHtml(comment.content)}</div>
                <div class="flex items-center gap-2">
                    <!-- 回复功能已移除 -->
                </div>
            </div>
        </div>
    `;
    
    return commentDiv;
}

// 检查登录状态
function checkLoginStatus() {
    // 检查是否有登录状态
    fetch('/api/users/current')
        .then(response => response.json())
        .then(data => {
            if (data.success && data.user) {
                isAdmin = data.user.role === 'admin';
                adminUser = data.user; // 保存管理员信息
                document.getElementById('user-status').textContent = isAdmin ? `以管理员身份评论 (${data.user.username})` : `以游客身份评论 (${data.user.username})`;
                document.getElementById('user-status').className = isAdmin ? 'text-sm text-red-600 font-medium' : 'text-sm text-gray-600';
            } else {
                isAdmin = false;
                adminUser = null;
                document.getElementById('user-status').textContent = '以游客身份评论';
                document.getElementById('user-status').className = 'text-sm text-gray-600';
            }
        })
        .catch(error => {
            // 如果检查失败，默认为游客
            isAdmin = false;
            document.getElementById('user-status').textContent = '以游客身份评论';
            document.getElementById('user-status').className = 'text-sm text-gray-600';
        });
}

// 设置评论处理器
function setupCommentHandlers() {
    const commentForm = document.getElementById('comment-form');
    
    // 表单提交事件
    commentForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const formData = new FormData(commentForm);
        const data = {
            author_name: isAdmin && adminUser ? (adminUser.name || adminUser.username) : '匿名用户',
            author_email: isAdmin && adminUser ? adminUser.email : 'anonymous@example.com',
            author_website: isAdmin && adminUser ? adminUser.website : null,
            content: formData.get('content'),
            post_id: parseInt(formData.get('post_id'))
        };
        
        
        // 验证必填字段
        if (!data.content) {
            if (typeof Utils !== 'undefined' && Utils.notification) {
                Utils.notification.show('请输入评论内容', 'warning');
            } else {
                alert('请输入评论内容');
            }
            return;
        }
        
        
        // 显示加载状态
        const submitBtn = document.getElementById('send-comment');
        const originalText = submitBtn.innerHTML;
        submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>提交中...';
        submitBtn.disabled = true;
        
        fetch('/api/comments', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data)
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                commentForm.reset();
                loadComments(); // 重新加载评论
                if (typeof Utils !== 'undefined' && Utils.notification) {
                    Utils.notification.show('评论提交成功，等待审核', 'success');
                } else {
                    alert('评论提交成功，等待审核');
                }
            } else {
                if (typeof Utils !== 'undefined' && Utils.notification) {
                    Utils.notification.show('提交失败：' + data.message, 'error');
                } else {
                    alert('提交失败：' + data.message);
                }
            }
        })
        .catch(error => {
            console.error('提交失败:', error);
            if (typeof Utils !== 'undefined' && Utils.notification) {
                Utils.notification.show('提交失败，请稍后重试', 'error');
            } else {
                alert('提交失败，请稍后重试');
            }
        })
        .finally(() => {
            submitBtn.innerHTML = '<i class="fas fa-paper-plane mr-2"></i>发表评论';
            submitBtn.disabled = false;
        });
    });
}

// 回复功能已移除

// 设置加载更多按钮
function setupLoadMoreButton() {
    // 在loadComments函数中已经处理了
}

// 设置点赞按钮
function setupLikeButton() {
    const likeBtn = document.getElementById('like-btn');
    const likeCount = document.querySelector('.like-count');
    
    // 检查元素是否存在
    if (!likeBtn) {
        console.error('点赞按钮元素未找到');
        return;
    }
    if (!likeCount) {
        console.error('点赞数元素未找到');
        return;
    }
    
    const postIdInput = document.getElementById('post-id-input');
    const currentPostId = postIdInput ? parseInt(postIdInput.value) : postId;
    
    likeBtn.addEventListener('click', function() {
        
        // 发送点赞请求
        fetch(`/api/posts/${currentPostId}/like`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            }
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                // 更新点赞数
                likeCount.textContent = data.like_count;
                // 添加点赞动画效果
                likeBtn.classList.add('animate-pulse');
                setTimeout(() => {
                    likeBtn.classList.remove('animate-pulse');
                }, 500);
            } else {
                alert('点赞失败：' + data.message);
            }
        })
        .catch(error => {
            console.error('点赞失败:', error);
            alert('点赞失败，请稍后重试');
        });
    });
}

// 加载文章统计数据
function loadPostStats() {
    // 获取文章统计信息
    const postIdInput = document.getElementById('post-id-input');
    const currentPostId = postIdInput ? parseInt(postIdInput.value) : postId;
    
    fetch(`/api/posts/${currentPostId}/stats`)
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                // 更新阅读数
                document.getElementById('view-count').textContent = `${data.view_count} 次阅读`;
                // 更新点赞数
                document.getElementById('like-count-display').textContent = `${data.like_count} 个赞`;
                document.querySelector('.like-count').textContent = data.like_count;
                // 更新评论数
                document.getElementById('comment-count-display').textContent = `${data.comment_count} 条评论`;
                document.getElementById('comment-count').textContent = data.comment_count;
            }
        })
        .catch(error => {
            console.error('加载统计数据失败:', error);
        });
}

// HTML转义函数
function escapeHtml(text) {
    const div = document.createElement('div');
    div.textContent = text;
    return div.innerHTML;
}
</script>

</body>
</html>